<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户新增</title>
	<link href="${ctxPath}/static/theme/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath}/static/theme/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    
    <link href="${ctxPath}/static/theme/css/animate.css" rel="stylesheet">
    <link href="${ctxPath}/static/theme/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${ctxPath}/static/theme/css/plugins/chosen/chosen.css" rel="stylesheet">
   
    <script src="${ctxPath}/static/theme/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxPath}/static/theme/js/jquery.form.js"></script>
    <script src="${ctxPath}/static/theme/js/plugins/chosen/chosen.jquery.js"></script>
</head>
<body>
  <div class="ibox">
    <div class="ibox-title">
      <h5>新建用户</h5>
      <div class="ibox-tools">
			<a title="返回" href="${ctxPath}/route/userList" class="btn btn-primary btn-xs"><i class="fa fa-reply"></i></a>
      </div>
    </div>
    <div class="ibox-content">
       <form class="form-horizontal m-t" id="user_edit" action="${ctxPath}/user/saveEditInfo">
        <div class="form-group">
          <label class="col-sm-1 control-label">用户名称：</label>
          <div class="col-sm-5">
          	<input type="hidden" name="id" value="${user.id}">
            <input type="text" name="name" class="form-control" value="${user.name}" readonly>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-1 control-label">登录名：</label>
          <div class="col-sm-5">
            <input type="text" name="loginId" class="form-control" value="${user.loginId}"  readonly>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-1 control-label">选择部门：</label>
          <div class="col-sm-3">
          	<input type="hidden" value="${user.deptId}">
          	<select id="dept" class="form-control chosen-select" name="deptId">
              <% for(dept in depts){ %>
              	<% if(user.deptId ==dept.id ){ %>
              		<option value="${dept.id}" selected>${dept.name}</option>
			  	<% }else{%>
					<option value="${dept.id}" >${dept.name}</option>
				<%}%>
			  <%}%>
            </select>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-1 control-label">电话：</label>
          <div class="col-sm-3">
            <input type="text" name="phone" class="form-control" placeholder="请输入联系人电话">
          </div>
        </div>
        <div class="form-group">
          <hr>
          <div class="col-sm-12 col-sm-offset-3">
            <button class="btn btn-primary" type="submit" id="submit-btn">保存</button>
            <a  href="${ctxPath}/route/userList" class="btn btn-white goback-btn">取消</a>
          </div>
        </div>
      </form>
    </div>
  </div>
  <script type="text/javascript">
  $(function(){
	  chosenInit();
	  $("#user_edit").ajaxForm({
          dataType: "json",
          beforeSend: function() {
          },
          uploadProgress: function(event, position, total, percentComplete) {
          },
          success: function() {
          },
          complete: function(xhr) {
        	  var data = xhr.responseText;
              data = JSON.parse(data);
              console.log(xhr);
              if (data.flag){
                 alert("修改成功");
            	 window.location="${ctxPath}/route/userList";
              } else{
              	alert(xhr.msg);
              }
          }
      });
	})
	
	// chosen初始化
    function chosenInit(chosenid) {
        $("body").find(".chosen-select").each(function () {
          $(this).chosen({
            disable_search_threshold: 1,
            no_results_text: "无相关记录",
            width: "100%",
            search_contains: true, // 从任意位置开始检索
            placeholder_text_single: "单选", allow_single_deselect: true,
            placeholder_text_multiple: "多选",
          });
        });
      }
  </script>
</body>
</html>